package com.xt.website_manager.dao;

import com.xt.website_manager.po.User;
import com.xt.website_manager.util.MyPageInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: jiangyu
 * @Date: 2019/9/2 11:33
 * @Description:
 */
@Mapper
public interface UserDao {

    /**
     * 登录校验
     */
    @Select("select * from tb_user where username=#{username} and password=#{password}")
    User findUserByUnameAndPwd(User user);


    /**
     * 查询全部用户
     */
    @Select("<script>select * from tb_user <where><if test='searchUsername != null'> and username like '%${searchUsername}%'</if></where> order by createtime desc</script>")
    List<User> findAllUsers(MyPageInfo<User> pageInfo);

    /**
     * 添加用户
     */
    @Insert("insert into tb_user values(default,#{username},#{password},#{sex},#{power},#{createtime})")
    void addUser(User user);

    /**
     * 查询用户名是否存在
     */
    @Select("select id from tb_user where username=#{username} limit 1")
    User checkUsername(String username);

    /**
     * 删除用户
     */
    @Delete("delete from tb_user where id=#{id}")
    void delUset(Integer id);

    /**
     *  查询用户详情
     */
    @Select("select * from tb_user where id = #{id}")
    User userDetails(Integer id);

    /**
     *  修改用户信息
     */
    @Update("update tb_user set username=#{username},password=#{password},sex=#{sex},power=#{power} where id = #{id}")
    void updateUser(User user);

}
